//页码变换

function pagechang(count, pagenum, page) {
	
	var pagelist = '';
	var lastpage = Math.ceil(count / pagenum)
	if(count > pagenum) {
		
		if(page > 6) {
			if(page > lastpage - 6) {
				pagelist = `<li>
							<a class='laquo'>&laquo;</a>
						</li>`
				pagelist += `<li>
								<a class='pageli'>1</a>
							</li>`
				pagelist += `<li>
								<a class='pageli'>2</a>
							</li>`
				pagelist += `<li class="disabled"><span>...</span></li>`
				for(var i = lastpage - 8; i < lastpage + 1; i++) {
					if(i == page) {
						pagelist += `<li class="active"><span>${i}</span></li>`
					} else {
						pagelist += `<li>
									<a class='pageli'>${i}</a>
								</li>`
					}
				}
				if(page == lastpage) {
					pagelist += `<li class="disabled"><span>&laquo;</span></li>`
				} else {
					pagelist += `<li>
								<a class='raquo'>&raquo;</a>
							</li>`
				};

			} else {
				pagelist = `<li>
							<a class='laquo'>&laquo;</a>
						</li>`
				pagelist += `<li>
								<a class='pageli'>1</a>
							</li>`
				pagelist += `<li>
								<a class='pageli'>2</a>
							</li>`
				pagelist += `<li class="disabled"><span>...</span></li>`
				for(var i = page - 3; i < page + 4; i++) {
					if(i == page) {
						pagelist += `<li class="active"><span>${i}</span></li>`
					} else {
						pagelist += `<li>
									<a class='pageli'>${i}</a>
								</li>`
					}
				}
				pagelist += `<li class="disabled"><span>...</span></li>`
				pagelist += `<li>
								<a class='pageli'>${lastpage-1}</a>
							</li>`
				pagelist += `<li>
					<a class='pageli'>${lastpage}</a>
				</li>`
				pagelist += `<li>
								<a class='raquo'>&raquo;</a>
							</li>`

			}
		} else {
			console.log(lastpage)
			if(page == 1 || !page) {
				pagelist = `<li class="disabled"><span>&laquo;</span></li>`
			} else {
				pagelist = `<li>
							<a class='laquo'>&laquo;</a>
						</li>`
			};
			if(lastpage <= 10) {
				for(var i = 0; i < lastpage; i++) {
					if((i + 1) == page) {
						pagelist += `<li class="active"><span>${i+1}</span></li>`
					} else {
						pagelist += `<li>
										<a class='pageli'>${i+1}</a>
									</li>`
					}
				}
			} else {
				for(var i = 0; i < 8; i++) {
					if((i + 1) == page) {
						pagelist += `<li class="active"><span>${i+1}</span></li>`
					} else {
						pagelist += `<li>
									<a class='pageli'>${i+1}</a>
								</li>`
					}
				}
				pagelist += `<li class="disabled"><span>...</span></li>`
				pagelist += `<li>
							<a class='pageli'>${lastpage-1}</a>
						</li>`
				pagelist += `<li>
				<a class='pageli'>${lastpage}</a>
			</li>`
			}

			if(page == lastpage) {
				pagelist += `<li class="disabled"><span>&raquo;</span></li>`
			} else {
				pagelist += `<li>
							<a class='laquo'>&raquo;</a>
						</li>`
			};
		}
		$('.pagination').html(pagelist)
		$('.pageli').on('click', function() {
			$('.page').val($(this).html())
			$('.search').click()
		})
	}
}